using System.Collections.Generic;
using Commons.Injector;
using Commons.Models.Settings.Dtos.Matchers;
using Commons.Models.Settings.Matchers;
using Commons.Models.Settings.Matchers.Operators;
using Commons.Utils.Extractors;

namespace Commons.Models.Settings.Mappers.Matchers
{
	public class RuleMapper : IMapper<RuleDto, IRule<object>>
	{
		public static IDataExtractor dataExtractor = DataExtractor.GetDefault();

		private RelationalOperatorMapper<object> operatorMapper = new RelationalOperatorMapper<object>();

		public IRule<object> Map(RuleDto config)
		{
			string key = config.Key;
			string[] values = config.Values.Split(',');
			IRelationalOperator<object> op = operatorMapper.Map(config.Operator);

			ValuePath valuePath = dataExtractor.GetValuePath(key);

			return new DataExtractorRule(op, valuePath, new List<string>(values));
		}
	}
}

